<template>
  <div class="sidebar-content">
    <h3>预览设备</h3>
    <div class="device-selector">
      <div 
        class="device-option" 
        :class="{ active: previewDevice === 'desktop' }"
        @click="$emit('deviceChange', 'desktop')"
      >
        <div class="device-icon">🖥️</div>
        <div class="device-name">桌面端</div>
        <div class="device-dimensions">{{ deviceDimensions }}</div>
      </div>
      <div 
        class="device-option" 
        :class="{ active: previewDevice === 'mobile' }"
        @click="$emit('deviceChange', 'mobile')"
      >
        <div class="device-icon">📱</div>
        <div class="device-name">手机</div>
        <div class="device-dimensions">375 × 667</div>
      </div>
    </div>
    
    <button class="preview-button" @click="$emit('openPreview')">
      在新窗口预览
    </button>
    
    <h3>导出设置</h3>
    <div class="export-settings">
      <div class="export-option">
        <label>格式</label>
        <select :value="exportFormat" @change="$emit('formatChange', $event.target.value)">
          <option value="png">PNG (透明背景)</option>
          <option value="jpg">JPG</option>
        </select>
      </div>
      
      <div class="export-option">
        <label>质量: {{ exportQuality }}%</label>
        <input 
          type="range" 
          min="10" 
          max="100" 
          step="1" 
          :value="exportQuality"
          @input="$emit('qualityChange', $event.target.value)"
        >
      </div>
      
      <div class="export-dimensions">
        <div class="dimension-row">
          <div class="dimension-item">
            <div class="dimension-label">宽度:</div>
            <input 
              class="dimension-input-field"
              type="number" 
              :value="exportWidth" 
              @change="$emit('dimensionChange', 'width', $event.target.value)"
            >
          </div>
          <div class="dimension-item">
            <div class="dimension-label">高度:</div>
            <input 
              class="dimension-input-field"
              type="number" 
              :value="exportHeight" 
              @change="$emit('dimensionChange', 'height', $event.target.value)"
            >
          </div>
        </div>
      </div>
      
      <div class="export-option">
        <label>
          <input 
            type="checkbox" 
            :checked="maintainAspectRatio" 
            @change="$emit('ratioChange', $event.target.checked)"
          >
          保持宽高比例
        </label>
      </div>
      
      <button class="export-button" @click="$emit('exportDesign')">
        导出设计
      </button>
    </div>
  </div>
</template>

<script>
export default {
  name: 'PreviewPanel',
  props: {
    previewDevice: {
      type: String,
      default: 'desktop'
    },
    deviceDimensions: {
      type: String,
      default: '1920 × 1080'
    },
    exportFormat: {
      type: String,
      default: 'png'
    },
    exportQuality: {
      type: Number,
      default: 90
    },
    exportWidth: {
      type: Number,
      default: 800
    },
    exportHeight: {
      type: Number,
      default: 600
    },
    maintainAspectRatio: {
      type: Boolean,
      default: true
    }
  }
}
</script>

<style scoped>
.sidebar-content {
  padding: 8px;
  overflow-y: auto;
  height: 100%;
  background-color: #f9fafc;
  scrollbar-width: thin;
}

/* 优化滚动条样式 */
.sidebar-content::-webkit-scrollbar {
  width: 6px;
}

.sidebar-content::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.15);
  border-radius: 3px;
}

.sidebar-content::-webkit-scrollbar-thumb:hover {
  background-color: rgba(0, 0, 0, 0.25);
}

h3 {
  font-size: 14px;
  margin-bottom: 8px;
  margin-top: 12px;
  color: #262626;
  font-weight: 500;
  position: relative;
  padding-left: 8px;
}

h3:first-child {
  margin-top: 6px;
}

h3::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 16px;
  background: linear-gradient(to bottom, #1890ff, #36cfc9);
  border-radius: 2px;
}

/* 简化标题下方的指示条 */
h3::after {
  content: "";
  display: block;
  position: absolute;
  left: 0;
  right: 0;
  bottom: -6px;
  height: 1px;
  background: linear-gradient(to right, rgba(24, 144, 255, 0.1), rgba(54, 207, 201, 0));
}

.device-selector {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.device-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 6px;
  background: #fff;
  border: 1px solid #e8e8e8;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 60px;
}

.device-option:hover {
  border-color: #40a9ff;
  box-shadow: 0 2px 8px rgba(24, 144, 255, 0.1);
}

.device-option.active {
  border-color: #1890ff;
  background: rgba(24, 144, 255, 0.05);
}

.device-option.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background: #1890ff;
}

.device-icon {
  font-size: 16px;
  margin-bottom: 2px;
  color: #595959;
}

.device-name {
  font-size: 12px;
  color: #262626;
  margin-bottom: 1px;
}

.device-dimensions {
  font-size: 11px;
  color: #8c8c8c;
}

.preview-button {
  width: 100%;
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  background: #f0f5ff;
  color: #1890ff;
  margin-bottom: 20px;
}

.preview-button:hover {
  background: #e6f7ff;
  border-color: #69c0ff;
}

.preview-button:active {
  background-color: #096dd9;
}

.export-settings {
  background: transparent;
  padding: 0;
  margin-top: 4px;
}

.export-option {
  margin-bottom: 8px;
}

.export-option label {
  font-size: 12px;
  color: #595959;
  margin-bottom: 2px;
}

.export-option select,
.export-option input[type="number"] {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #d9d9d9;
  border-radius: 4px;
  font-size: 13px;
  transition: all 0.2s;
}

.export-option select:hover,
.export-option input[type="number"]:hover {
  border-color: #40a9ff;
}

.export-option select:focus,
.export-option input[type="number"]:focus {
  border-color: #1890ff;
  outline: none;
  box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.1);
}

.export-dimensions {
  margin-bottom: 10px;
}

.dimension-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.dimension-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.dimension-label {
  font-size: 12px;
  color: #595959;
  white-space: nowrap;
}

.dimension-input-field {
  width: 60px !important;
  height: 24px !important;
  padding: 0 4px !important;
  font-size: 12px !important;
  border: 1px solid #d9d9d9 !important;
  border-radius: 4px !important;
  text-align: center !important;
  -moz-appearance: textfield !important;
  -webkit-appearance: none !important;
  box-sizing: border-box !important;
}

.dimension-input-field::-webkit-outer-spin-button,
.dimension-input-field::-webkit-inner-spin-button {
  -webkit-appearance: none !important;
  margin: 0 !important;
}

.dimension-input-field:hover {
  border-color: #40a9ff !important;
}

.dimension-input-field:focus {
  border-color: #1890ff !important;
  outline: none !important;
  box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.1) !important;
}

.export-button {
  width: 100%;
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  background: #52c41a;
  color: white;
  margin-top: 8px;
}

.export-button:hover {
  background: #73d13d;
}

/* 质量滑块样式优化 */
input[type="range"] {
  width: 100%;
  height: 4px;
  background: #f0f0f0;
  border-radius: 2px;
  outline: none;
  -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: #1890ff;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.1);
  box-shadow: 0 0 0 4px rgba(24, 144, 255, 0.1);
}

/* 复选框样式优化 */
input[type="checkbox"] {
  margin-right: 6px;
  position: relative;
  top: 1px;
}

/* 响应式调整：在较小的视口高度下压缩UI */
@media (max-height: 768px) {
  h3 {
    margin-top: 16px;
    margin-bottom: 10px;
    font-size: 14px;
  }
  
  .device-selector {
    margin-bottom: 14px;
  }
  
  .device-option {
    height: 75px;
  }
  
  .preview-button {
    margin-bottom: 14px;
    height: 32px;
  }
  
  .export-settings {
    padding: 10px;
  }
  
  .export-option {
    margin-bottom: 10px;
  }
  
  .export-dimensions {
    margin-bottom: 10px;
  }
  
  .dimension-input-field {
    padding: 4px 6px;
  }
  
  .export-dimensions::after {
    margin-top: 8px;
  }
}
</style> 